package com.sgai.zero_robot.pop;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.MutableLiveData;
import com.sgai.zero_robot.R;

public class SettingVideoView extends FrameLayout {
    private final String TAG = "SettingVideoView";
    public  static MutableLiveData<Boolean> recordVideo = new MutableLiveData<>(false);
    private ImageView ivVideoRecord;

    public SettingVideoView(@NonNull Context context) {
        this(context,null);
    }

    public SettingVideoView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,-1);
    }

    public SettingVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }
    private void setChecked(boolean checked){
        if (checked){
            ivVideoRecord.setImageResource(R.mipmap.video_checked);
        }else{
            ivVideoRecord.setImageResource(R.mipmap.video_unchecked);
        }
    }
    private void init(Context context){
        View view = inflate(context, R.layout.setting_video, this);
        ivVideoRecord = view.findViewById(R.id.iv_video_record);
        setChecked(recordVideo.getValue());
        ivVideoRecord.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag = !recordVideo.getValue();
                recordVideo.postValue(flag);
                setChecked(flag);
            }
        });
    }
}
